package com.itheima.controller;

import com.itheima.client.ClientPage;
import com.itheima.client.orderpojo.Vo.OrderHistoryVo;
import com.itheima.client.orderpojo.dto.OrderDto;
import com.itheima.common.JsonResult;
import com.itheima.service.ClientOrderService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;

/**
 * @author wuzhiyong
 */
@RestController
@RequestMapping(value = "/order")
public class ClientOrderController {
    @Autowired
    private ClientOrderService clientOrderService;

    /**
     * 提交订单
     * @param orderDto orderDto
     * @return JsonResult
     */
    @PostMapping(value = "/submit")
    public JsonResult<Boolean> orderSubmit(@RequestBody OrderDto orderDto){
        boolean order = clientOrderService.addOrder(orderDto);
        if (order){
            return JsonResult.success(order, null);
        }

        return JsonResult.error("提交失败");
    }

    /**
     * 订单列表
     * @param page page
     * @param pageSize pageSize
     * @return JsonResult
     */
    @GetMapping(value = "/userPage")
    public JsonResult<Object> orderUserPage( @RequestParam(value = "page") Integer page, @RequestParam(value = "pageSize") Integer pageSize) {
        ClientPage<OrderHistoryVo> orderPage = clientOrderService.getOrderPage(page, pageSize);
        if (orderPage !=null){
            return JsonResult.success(orderPage, null);
        }
        return JsonResult.error(null);
    }



}
